<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改讲座报告')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <style>
        .form-group{
            flex: 0 0 50%;
            box-sizing: border-box;
        }
        .card{
            display: flex;
            flex-wrap: wrap;
        }
    </style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-report-edit" th:object="${sciLectureReport}">
            <!--状态-->
            <input id="state" th:field="*{state}" type="hidden">
            <!--批阅或核查的标识-->
            <input name="urlFlag" id="urlFlag" th:field="*{urlFlag}" type="hidden">
            <!--被批阅的表单或报告的id-->
            <input name="id" id="report_id" th:field="*{id}" type="hidden">
<!--            <input name="id" th:field="*{id}" type="hidden">-->
            <div class="card">

                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">申请人：</label>
                    <div class="col-sm-8">
                        <!--                    <input name="teacherName" class="form-control" type="text" required>-->
                        <input name="userId" class="form-control" type="hidden" th:field="*{userId}">
                        <input class="form-control" type="text" th:field="*{teacherName}" readonly>

<!--                        <select name="userId" class="form-control m-b" >-->
<!--                            <option th:each="user : ${sysUsers}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${user.userId == sciLectureReport.userId}"></option>-->
<!--                        </select>-->
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label">讲座主题：</label>
                    <div class="col-sm-8">
                        <input name="reportTheme" th:field="*{reportTheme}" class="form-control" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">讲座题目：</label>
                    <div class="col-sm-8">
                        <input name="reportSubject" th:field="*{reportSubject}" class="form-control" type="text" required>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">主办单位：</label>
                    <div class="col-sm-8">
                        <input name="hostUnit" th:field="*{hostUnit}" class="form-control" type="text" required>
                    </div>
                </div>


                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">讲座时间：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="reportTime" autocomplete="off" th:field="*{reportTime}" th:value="${#dates.format(reportTime, 'yyyy-MM-dd hh:ii')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">讲座地点：</label>
                    <div class="col-sm-8">
                        <input name="reportPlace" th:field="*{reportPlace}" class="form-control" type="text" required>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">参与人数：</label>
                    <div class="col-sm-8">
                        <input name="reportNumber" th:field="*{reportNumber}" class="form-control" type="text">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label">报告时长：</label>
                    <div class="col-sm-8">
                        <input name="reportDuration" th:field="*{reportDuration}" class="form-control" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">分类：</label>
                    <div class="col-sm-8">
<!--                        <input name="reportClassify" th:field="*{reportClassify}" class="form-control" type="text">-->
                        <select name="reportClassify" class="form-control m-b" required>
                            <option value="">请选择</option>
                            <option th:each="reportIntegral : ${reportIntegralList}" th:text="${reportIntegral.classification}" th:value="${reportIntegral.id}" th:selected="${reportIntegral.id == sciLectureReport.repIntId}"></option>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">资料：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="reportUrl" th:field="*{reportUrl}">
                        <div class="file-loading">
                            <input class="form-control file-upload" id="reportUrl" name="file" type="file">
                        </div>
                    </div>
                </div>

            </div>

            <h4 class="form-header h4 tdiv2"  style="display:none;">退回记录</h4>
            <div class="row tdiv2" style="display:none;">
                <div class="col-sm-12">

                    <div class="form-group"  >
                        <table id='bootstrap-table'></table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "system/report";
        $("#form-report-edit").validate({
            focusCleanup: true
        });


        // 当被退回后进行更新时显示退回记录
        $(function(){
            var rid = $("#report_id").val();
            // alert("审批的讲座报告id："+rid)
            console.log("当前审批的讲座报告id为："+rid)
            var options = {
                url: prefix + "/opinion/"+rid,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                pagination:false,
                columns: [

                    {
                        field : 'createTime',
                        title : '批阅时间',
                        width: 200

                    } ,
                    {
                        field : 'uname',
                        title : '批阅人',
                        width: 100
                    },
                    {
                        field : 'concate',
                        title : '内容',
                        width: 500
                    },
                    {
                        field : 'state',
                        title : '审核状态',
                        width: 100
                    } ]
            };
            $.table.init(options);

            $('#bootstrap-table').on('load-success.bs.table', function (e, name, args) {
                console.log('Event Name:', name.rows);

                var a =$("#state").val();
                // alert("状态为:"+a)
                if(a != 1){
                    if(name.rows.length > 0){
                        $(".tdiv2").show();
                    }
                }

            });
        })

        // 修改保存方法
        function submitHandler() {
            if ($.validate.form()) {
                $.operate.saveTab(prefix + "/edit", $('#form-report-edit').serialize());
            }
        }

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload/jzbg',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true,
                allowedFileExtensions: ["pdf"], // 只允许上传PDF文件
                slugCallback: function (filename) {
                    // 自定义文件名生成规则
                    if ($("input[name='reportSubject']").val() === "") {
                        $(".file-uploada").fileinput('clear'); // 清空文件选择
                        $.modal.alertError("请先填写讲座题目"); // 弹出错误提示
                        return false; // 阻止上传
                    }
                    // 自定义文件名生成规则
                    fileExtension = filename.split('.').pop(); // 获取文件扩展名
                    const year = new Date().getFullYear(); // 获取当前年份
                    const newName = year + "-" + $("input[name='reportSubject']").val() + "-" + "资料" + "." + fileExtension; // 生成新文件名
                    return newName; // 返回新文件名
                },
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });

        // $("input[name='reportTime']").datetimepicker({
        //     format: "yyyy-mm-dd",
        //     minView: "month",
        //     autoclose: true
        // });

        $("input[name='reportTime']").datetimepicker({
            format: "yyyy-mm-dd hh:ii",
            minView: "hour",
            autoclose: true
        });
    </script>
</body>
</html>